
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="com.kma.ncpractice2013.dao.UserDAO" %>
<%@ page import="com.kma.ncpractice2013.model.User" %>
<%@ page import="com.kma.ncpractice2013.dao.UserGroupDAO" %>
<%@ page import="com.kma.ncpractice2013.model.UserGroup" %>
<%@ page import="com.kma.ncpractice2013.model.Commission" %>
<%
    String sessionAuth = (String)session.getAttribute("auth");
    double dsc = 0;
    double comm = 0;
    double bonus = 0;
    User user = null;
    String username = "";
    if(sessionAuth !=null && sessionAuth.equals("true"))
    {


        //String username = (String)session.getAttribute("username");
        //int userAccessLevel = Integer.parseInt((String)session.getAttribute("access_level"));
        //UserDAO userDAO = new UserDAO();
        user = (User)session.getAttribute("user");
        UserGroupDAO userGroupDAO = new UserGroupDAO();
        UserGroup userGroup = userGroupDAO.getById(user.getGroupId().getValue());
        dsc = userGroup.getDiscount();
        //comm = userGroup.getCommission();

        comm = Commission.getValue();
        bonus = user.getBonus();
        username = user.getLogin();

    }
%>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Main page</title>
<link rel="stylesheet" href="main_page.css" />
<link rel="stylesheet" href="paging.css" />
<link rel="stylesheet" href="https://code.jquery.com/ui/1.10.3/themes/start/jquery-ui.css" />
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
<script src="https://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<script type="text/javascript" src="paging.js"></script>
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script>
<script>
var res;
var promocodeDiscount = 0;
var discount = "<%=dsc%>";
var commission = "<%=comm%>";
var sessionAuth = "<%=sessionAuth%>";
</script>
<script type="text/javascript" src="main_page.js"></script>

<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta charset="utf-8">
</head>

<body>

<div id="header-wrapper">
<div id="header" class="container">
	<div id="logo">
    	<h1><a href="#">Accommodation</a></h1>
    </div>
    <%

            String b = (String)session.getAttribute("auth");
            if(b!=null && b.equals("true"))
            {

                out.print("<div id=\"auth\"><form>" +
				"Welcome, <a href='/user/userProfile.jsp'>"+ 
				user.getName() + "</a> | " +
                                  "<a href=\"logout.jsp\">Log out</a>" +
						  "</form></div>\n");
            }

        else
        out.print("<div id=\"auth\">" +
                                  "<form method=\"post\" action=\"Auth\">"+
                          "        <input size=\"20\" type=\"text\" placeholder=\"e-mail\" name=\"username\">\n" +

                          "        <input size=\"15\" type=\"password\" placeholder=\"password\" name=\"password\">\n" +
                          "        <input type=\"submit\" value=\"Log in\"> \n" +
						  "        <a href=\"/openid?op=Google\"><img src=\"google_logo.jpg\" id=\"openid-image\" title=\"Login via OpenID account\"></a> \n" + 
                          "        <a id=\"regist\" href=\"register.jsp\">Register</a>\n" +
                                "</form>"+
						  "        <br clear=\"all\"><a id=\"reset_pass\" href=\"resetPassword.jsp\">Forgot your password?</a>\n" +
                          "    </div>\n");
    %>


</div>
</div>

<div id="menu-wrapper">
<div id="menu" class="container">
<%



	if(b!=null && b.equals("true") && user != null)
	{
		User.AccessLevel accessLevel = user.getAccessLevelId();
		if (accessLevel == User.AccessLevel.administrator)
		{
			out.print("<ul>\n"+
			 "<li class=\"active\"><a href=\"/main_page.jsp\">Main page</a></li>\n" + 
			 "<li><a href=\"/user/userProfile.jsp\">Profile</a></li>\n" +
			 "<li><a href=\"/admin/dashboard.jsp\">Admin's dashboard</a></li>\n" +
				"</ul>\n");
		}
		else if (accessLevel == User.AccessLevel.manager)
		{
			out.print("<ul>\n"+
			 "<li class=\"active\"><a href=\"/main_page.jsp\">Main page</a></li>\n" + 
			 "<li><a href=\"/user/userProfile.jsp\">Profile</a></li>\n" +
			 "<li><a href=\"/manager/discounts.jsp\">Comissions and discounts</a></li>\n" +
			 "<li><a href=\"/manager/promocodes.jsp\">Promo-codes</a></li>\n" +
			 "<li><a href=\"/manager/vipstatus.jsp\">VIP-status</a></li>\n" +
			 "<li><a href=\"/manager/reports.jsp\">Reports</a></li>\n" +
				"</ul>\n");
		}
		else
		{
			out.print("<ul>\n"+
			 "<li class=\"active\"><a href=\"/main_page.jsp\">Main page</a></li>\n" + 
			 "<li><a href=\"/user/userProfile.jsp\">Profile</a></li>\n" +
			 "</ul>\n");
		}
	}
%>
</div>
</div>

<div id="content-wrapper">
<div id="content" class="container">
    <div id="search-part">
    <div class="left-column"><header>Search hotels</header></div>
    <div id="right-preloader"><img src="/482.GIF" /></div>
    <br clear="all">
    <ul>
        <li>Location: <input placeholder="Place" type="search" id="dest" size="51" />
        </li>
        <li><div id="check-in">Check-in: <input type="text" id="checkin" size="15" readonly/></div>
        <div id="check-out">Check-out: <input type="text" id="checkout" size="15" readonly/></div></li>
    </ul>
    <div class="left-column">
        <ul style="margin-top:0">
        <li>Rooms
        <select id="rooms">
          <option value="1">1</option>
          <option value="2">2</option>
          <option value="3">3</option>
          <option value="4">4</option>
        </select>
        </li>
        
        <li>Adults
        <select id="adults">
          <option value="1">1</option>
          <option value="2">2</option>
          <option value="3">3</option>
          <option value="4">4</option>
        </select>
        </li>    
        
        <li>Children
        <select id="children">
          <option value="0">none</option>
          <option value="1">1</option>
          <option value="2">2</option>
          <option value="3">3</option>
          <option value="4">4</option>
        </select>
        </li>
        <li>Payment method<br>
            <select id="payment_method">
                <option value="bonus">pay with bonuses - <%=bonus%> available</option>
                <option value="method1">method 1</option>
                <option value="method2">method 2</option>
            </select>
            <div id="emaildiv" style="right: 10px;"></div>
    	</li>
    </ul>
    </div>
    <div id="right-button">
    	<a href="javascript:MakeQuery()" class="button" id="bsearch">Search!</a>
    </div>
    </div>
    
    <div id="map-canvas">

    </div>
</div>
</div>

<div id="result-wrapper">
<div id="results" class="container">
	<div id="caption">
    	<header>Search results: <span type="text" id="results-count"></span></header>
        <div id="promocode">
        	Enter the promo-code: <input type="text" size="7" >
            <input type="button" value="Submit" onClick="yourFunc()" >
        </div>
    </div>
    <br clear="all">
    <div id="result-table"><table>
    	<thead><tr>
        	<td>#</td>
            <td>Neighbourhood</td>
            <td>Price</td>
            <td>Price with discount</td>
            <td>Star rating</td>
            <td>Make the order</td>
            <td>Map</td>
        </tr></thead>
        <tbody id="result_body">

        </tbody>
    </table></div>
    <div id="pageNavPosition" class="pageNavigation"></div>
</div>
</div>

<div id="copyright-wrapper">
<div id="copyright" class="container">
<p>Copyright (c) 2013. All rights reserved.</p>
</div>
</div>

</body>

</html>
